Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Edit Proceed to Checkout button #7733

Merged
merged 7 commits into from
Dec 13, 2022
Merged

Conversation

alexflorisca
Copy link
Member

@alexflorisca alexflorisca commented Nov 22, 2022

This PR adds the ability to edit the Proceed to Checkout button on the Cart block.

Challenges to solve:

  • With the current implementation, we loose the translations of the button

This was due to the default attribute not being a translatable string. I've now added this in, but for some reason I can't get ANYTHING to translate. @nielslange maybe you can help me out here a little?

  • We're also duplicating the Button in edit.tsx, minus a few props. IS there a better way to do this?

We're not REALLY duplicating the button, we are just wrapping the RichText component in a <Button className="wc-block-cart__submit-button"> to give it the right styling. I think this is ok, doesn't duplicate any of the props passed to the button in block.tsx and simplifies the code by not having to wrap the component in a <NonInteractive> component

  • You can insert multi line text in the button which shows up as <br /> in the front end

This seems to be a bug with the RichText editor, as the multiline prop is supposed to restrict input to one line only. Will investigate this with Gutenberg.

Fixes #7012

Accessibility

Other Checks

  • This PR adds/removes a feature flag & I've updated this doc.
  • This PR adds/removes an experimental interfaces and I've updated this doc.
  • I tagged two reviewers because this PR makes queries to the database or I think it might have some security impact.

Testing

Automated Tests

  • Changes in this PR are covered by Automated Tests.
    • Unit tests
    • E2E tests

User Facing Testing

  1. Open up the Cart page in the editor
  2. Click on the Proceed to Checkout button. You should be able to edit the text of this button
  3. Edit the text and press "Update"
  4. Visit the Cart page on the front end and make sure the changes are visible
  • Do not include in the Testing Notes

WooCommerce Visibility

  • WooCommerce Core
  • Feature plugin
  • Experimental

Performance Impact

Changelog

Enhancement: Enable merchants to adjust the label of the Proceed to Checkout button according to their needs.

@github-actions
Copy link
Contributor

The release ZIP for this PR is accessible via:

https://wcblocks.wpcomstaging.com/wp-content/uploads/woocommerce-gutenberg-products-block-7733.zip

@github-actions
Copy link
Contributor

github-actions bot commented Nov 22, 2022

TypeScript Errors Report

Files with errors: 427
Total errors: 2058

🎉 🎉 This PR does not introduce new TS errors.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 22, 2022

Size Change: -360 B (0%)

Total Size: 972 kB

Filename Size Change
build/all-products-frontend.js 11.3 kB +4 B (0%)
build/all-products.js 33.1 kB -11 B (0%)
build/all-reviews.js 7.79 kB +1 B (0%)
build/attribute-filter.js 12.3 kB -3 B (0%)
build/cart-blocks/cart-accepted-payment-methods-frontend.js 1.38 kB -1 B (0%)
build/cart-blocks/cart-cross-sells-products--product-add-to-cart-frontend.js 5.48 kB +3 B (0%)
build/cart-blocks/cart-express-payment--checkout-blocks/express-payment-frontend.js 5.04 kB -1 B (0%)
build/cart-blocks/cart-express-payment-frontend.js 778 B -1 B (0%)
build/cart-blocks/cart-items-frontend.js 299 B +1 B (0%)
build/cart-blocks/cart-line-items--mini-cart-contents-block/products-table-frontend.js 5.29 kB -1 B (0%)
build/cart-blocks/cart-line-items-frontend.js 1.07 kB -1 B (0%)
build/cart-blocks/cart-order-summary-frontend.js 1.24 kB +1 B (0%)
build/cart-blocks/filled-cart-frontend.js 782 B +1 B (0%)
build/cart-blocks/order-summary-coupon-form-frontend.js 1.73 kB +2 B (0%)
build/cart-blocks/order-summary-discount-frontend.js 2.15 kB -1 B (0%)
build/cart-blocks/order-summary-shipping-frontend.js 5.99 kB +1 B (0%)
build/cart-blocks/order-summary-taxes-frontend.js 435 B -1 B (0%)
build/cart-blocks/proceed-to-checkout-frontend.js 1.24 kB +45 B (+4%)
build/cart-frontend.js 46.2 kB -1 B (0%)
build/cart.js 45.9 kB -389 B (-1%)
build/checkout-blocks/actions-frontend.js 1.77 kB -1 B (0%)
build/checkout-blocks/billing-address--checkout-blocks/shipping-address-frontend.js 3.9 kB +2 B (0%)
build/checkout-blocks/billing-address-frontend.js 1.09 kB +2 B (0%)
build/checkout-blocks/fields-frontend.js 343 B -1 B (0%)
build/checkout-blocks/order-note-frontend.js 1.14 kB +1 B (0%)
build/checkout-blocks/order-summary-cart-items-frontend.js 3.67 kB -1 B (0%)
build/checkout-blocks/order-summary-coupon-form-frontend.js 1.89 kB -1 B (0%)
build/checkout-blocks/order-summary-discount-frontend.js 2.28 kB +2 B (0%)
build/checkout-blocks/order-summary-frontend.js 1.24 kB -1 B (0%)
build/checkout-blocks/order-summary-shipping-frontend.js 6.04 kB +1 B (0%)
build/checkout-blocks/payment-frontend.js 8.31 kB -1 B (0%)
build/checkout-blocks/shipping-address-frontend.js 1.07 kB +2 B (0%)
build/checkout-blocks/shipping-methods-frontend.js 5.01 kB +1 B (0%)
build/checkout-blocks/terms-frontend.js 1.63 kB -4 B (0%)
build/checkout-blocks/totals-frontend.js 325 B +1 B (0%)
build/checkout-frontend.js 48.3 kB +9 B (0%)
build/featured-category.js 13.2 kB +2 B (0%)
build/featured-product.js 13.4 kB +1 B (0%)
build/filter-wrapper-frontend.js 13.8 kB -3 B (0%)
build/filter-wrapper.js 2.4 kB +2 B (0%)
build/handpicked-products.js 7.29 kB +1 B (0%)
build/legacy-template.js 2.85 kB +2 B (0%)
build/mini-cart-component-frontend.js 20 kB +5 B (0%)
build/mini-cart-contents-block/footer-frontend.js 2.95 kB +2 B (0%)
build/mini-cart-contents-block/products-table-frontend.js 591 B +1 B (0%)
build/mini-cart-contents-block/shopping-button-frontend.js 288 B -1 B (0%)
build/mini-cart-contents.js 17.1 kB +5 B (0%)
build/mini-cart.js 4.28 kB -1 B (0%)
build/price-filter-wrapper-frontend.js 7.02 kB -1 B (0%)
build/price-filter.js 8.37 kB -2 B (0%)
build/product-add-to-cart-frontend.js 1.46 kB -1 B (0%)
build/product-add-to-cart.js 8.37 kB +1 B (0%)
build/product-best-sellers.js 7.62 kB +3 B (0%)
build/product-category-list-frontend.js 1.13 kB -1 B (0%)
build/product-category.js 8.62 kB -1 B (0%)
build/product-on-sale.js 7.95 kB -1 B (0%)
build/product-query.js 4.44 kB +1 B (0%)
build/product-sku.js 376 B -1 B (0%)
build/product-stock-indicator.js 645 B -1 B (0%)
build/product-summary-frontend.js 1.52 kB -2 B (0%)
build/product-summary.js 920 B -1 B (0%)
build/product-tag-list.js 497 B -1 B (0%)
build/product-tag.js 8.01 kB +4 B (0%)
build/product-title.js 3.3 kB -1 B (0%)
build/product-top-rated.js 7.87 kB +2 B (0%)
build/products-by-attribute.js 8.54 kB +3 B (0%)
build/rating-filter-wrapper-frontend.js 5.41 kB -1 B (0%)
build/rating-filter.js 5.79 kB -4 B (0%)
build/reviews-by-category.js 11.2 kB +5 B (0%)
build/reviews-by-product.js 12.3 kB +3 B (0%)
build/single-product-frontend.js 17.5 kB +5 B (0%)
build/single-product.js 10 kB -2 B (0%)
build/stock-filter.js 6.7 kB -4 B (0%)
build/vendors--cart-blocks/cart-cross-sells-products--cart-blocks/order-summary-shipping--checkout-blocks--18f9376a-frontend.js 19.1 kB +5 B (0%)
build/vendors--cart-blocks/cart-cross-sells-products--product-add-to-cart-frontend.js 7.54 kB +1 B (0%)
build/vendors--cart-blocks/order-summary-shipping--checkout-blocks/billing-address--checkout-blocks/order--5b8feb0b-frontend.js 4.85 kB +3 B (0%)
build/wc-blocks-vendors.js 62.3 kB -45 B (0%)
build/wc-blocks.js 2.63 kB -1 B (0%)
ℹ️ View Unchanged
Filename Size
build/active-filters-frontend.js 7.74 kB
build/active-filters-wrapper-frontend.js 6.01 kB
build/active-filters.js 7.32 kB
build/attribute-filter-frontend.js 22.6 kB
build/attribute-filter-wrapper-frontend.js 7.14 kB
build/blocks-checkout.js 27.1 kB
build/cart-blocks/cart-cross-sells-frontend.js 253 B
build/cart-blocks/cart-cross-sells-products-frontend.js 4.76 kB
build/cart-blocks/cart-totals-frontend.js 319 B
build/cart-blocks/empty-cart-frontend.js 346 B
build/cart-blocks/order-summary-fee-frontend.js 273 B
build/cart-blocks/order-summary-heading-frontend.js 455 B
build/cart-blocks/order-summary-subtotal-frontend.js 274 B
build/checkout-blocks/contact-information-frontend.js 1.79 kB
build/checkout-blocks/express-payment-frontend.js 1.13 kB
build/checkout-blocks/order-summary-fee-frontend.js 276 B
build/checkout-blocks/order-summary-subtotal-frontend.js 273 B
build/checkout-blocks/order-summary-taxes-frontend.js 436 B
build/checkout.js 40.3 kB
build/general-style-rtl.css 1.29 kB
build/general-style.css 1.29 kB
build/mini-cart-contents-block/empty-cart-frontend.js 366 B
build/mini-cart-contents-block/filled-cart-frontend.js 230 B
build/mini-cart-contents-block/items-frontend.js 237 B
build/mini-cart-contents-block/title-frontend.js 368 B
build/mini-cart-frontend.js 1.88 kB
build/price-filter-frontend.js 13.6 kB
build/price-format.js 1.19 kB
build/product-add-to-cart--product-button--product-category-list--product-image--product-price--product-r--a0326d00.js 227 B
build/product-add-to-cart--product-button--product-image--product-rating--product-title.js 151 B
build/product-button--product-category-list--product-image--product-price--product-rating--product-sale-b--e17c7c01.js 432 B
build/product-button--product-image--product-rating--product-sale-badge--product-title.js 301 B
build/product-button-frontend.js 2.17 kB
build/product-button.js 3.85 kB
build/product-categories.js 2.36 kB
build/product-category-list.js 502 B
build/product-image-frontend.js 2.16 kB
build/product-image.js 3.93 kB
build/product-new.js 7.62 kB
build/product-price-frontend.js 2.15 kB
build/product-price.js 1.53 kB
build/product-rating-frontend.js 1.47 kB
build/product-rating.js 815 B
build/product-sale-badge-frontend.js 1.38 kB
build/product-sale-badge.js 816 B
build/product-search.js 2.62 kB
build/product-sku-frontend.js 629 B
build/product-stock-indicator-frontend.js 1.26 kB
build/product-tag-list-frontend.js 1.12 kB
build/product-title-frontend.js 1.57 kB
build/rating-filter-frontend.js 7.16 kB
build/reviews-frontend.js 7.02 kB
build/stock-filter-frontend.js 7.8 kB
build/stock-filter-wrapper-frontend.js 6.04 kB
build/vendors--attribute-filter-wrapper--mini-cart-contents-block/footer--product-add-to-cart-frontend.js 6.86 kB
build/vendors--attribute-filter-wrapper-frontend.js 8.2 kB
build/vendors--cart-blocks/cart-cross-sells-products--cart-blocks/cart-line-items--cart-blocks/cart-order--671ca56f-frontend.js 5.26 kB
build/vendors--cart-blocks/cart-line-items--checkout-blocks/order-summary-cart-items--mini-cart-contents---233ab542-frontend.js 3.14 kB
build/vendors--cart-blocks/order-summary-shipping--checkout-blocks/order-summary-shipping--checkout-block--dda5866c-frontend.js 8.85 kB
build/wc-blocks-data.js 18.7 kB
build/wc-blocks-editor-style-rtl.css 5.19 kB
build/wc-blocks-editor-style.css 5.19 kB
build/wc-blocks-google-analytics.js 1.56 kB
build/wc-blocks-middleware.js 934 B
build/wc-blocks-registry.js 2.92 kB
build/wc-blocks-shared-context.js 1.52 kB
build/wc-blocks-shared-hocs.js 1.73 kB
build/wc-blocks-style-rtl.css 24.2 kB
build/wc-blocks-style.css 24.1 kB
build/wc-blocks-vendors-style-rtl.css 1.95 kB
build/wc-blocks-vendors-style.css 1.95 kB
build/wc-payment-method-bacs.js 816 B
build/wc-payment-method-cheque.js 811 B
build/wc-payment-method-cod.js 909 B
build/wc-payment-method-paypal.js 837 B
build/wc-settings.js 2.6 kB

compressed-size-action

@nielslange
Copy link
Member

@alexflorisca I know this PR is still in draft, but I took a brief look and noticed two things:

  • Currently, it's possible to remove the Proceed to Checkout text and save the button without any text. If a merchant deletes the text, I think we could use the default text as a fallback then.
  • I noticed that the button is no longer translatable. Your implementation looks good, and unfortunately, I cannot explain what might causes this.

@alexflorisca alexflorisca marked this pull request as ready for review November 28, 2022 17:08
@rubikuserbot rubikuserbot requested a review from a team November 28, 2022 17:09
@alexflorisca
Copy link
Member Author

Thanks for your comment Niels! So I've made some changes and you can officially review it!

I added your suggestion and the user now can't save an empty button. It will default to Proceed to Checkout if the button is empty.

I've also translated the default text for the button, so hopefully that should work now, but for some reason I can't get anything to translate on my local test side. Could use your help here.

There's also another bug with the RichText editor where it allows you to insert line breaks, even when the multiline prop is false. I'll raise this with Gutenberg directly

Let me know what you think,

@nielslange
Copy link
Member

Thanks for applying the changes, @alexflorisca!

I added your suggestion and the user now can't save an empty button. It will default to Proceed to Checkout if the button is empty.

Nice! This change works as expected both for English and non-English strings. On my end, I tested it both for de_DE and nl_NL and when removing the corresponding translation of the button text, the translation appears again.

I've also translated the default text for the button, so hopefully that should work now, but for some reason I can't get anything to translate on my local test side. Could use your help here.

Happy to jump on a call with you to sort this out. Sometimes translations act a bit strange. What I do, occasionally, is resetting the translations. You can do that as follows:

  1. Head over to the folder where the languages of your site are stored, e.g. /Users/alexflorisca/Sites/store/wp-content/languages/.
  2. Delete all languages both in languages/, languages/plugins and languages/themes.

This will reset all translations, and you can run a fresh installation of the desired language via https://store.test/wp-admin/options-general.php.

There's also another bug with the RichText editor where it allows you to insert line breaks, even when the multiline prop is false. I'll raise this with Gutenberg directly.

Sounds good. I'd probably add the issue number to this ticket in case we're looking up this ticket in the future. That said, I'd not wait for the upstream fix, but go ahead and deploy this PR already. I assume once this issue got addressed in upstream, we'll automatically receive the change and there's nothing for us to adjust, given that you're already calling multiline={ false }.

Copy link
Member

@nielslange nielslange left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, @alexflorisca! 🙌 I'm pre-approving this PR as it works as expected, incl. the translations. I just left a minor suggestion regarding where to store the default button label.

Comment on lines 19 to 23
export const defaultButtonLabel = __(
'Proceed to Checkout',
'woo-gutenberg-products-block'
);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexflorisca I wonder if we should move the button label into a designated file, e.g. constants.tsx. We're doing the same for the product elements currently:

export const BLOCK_TITLE: string = __(
'Product Image',
'woo-gutenberg-products-block'
);
export const BLOCK_ICON: JSX.Element = (
<Icon icon={ image } className="wc-block-editor-components-block-icon" />
);
export const BLOCK_DESCRIPTION: string = __(
'Display the main product image.',
'woo-gutenberg-products-block'
);

That way, we keep block.tsx lean, and we can still use the translatable string both in block.tsx and in attributes.tsx.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only move things to constants file when they're dynamic, this string should be in attributes.jsx or block.json

@github-actions github-actions bot added this to the 9.1.0 milestone Nov 30, 2022
Comment on lines 76 to 86
onChange={ ( content ) => {
if ( content === '' ) {
setAttributes( {
buttonLabel: defaultButtonLabel,
} );
} else {
setAttributes( {
buttonLabel: content,
} );
}
} }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this effort, why are we setting the attribute back to its default value? I understand that you're trying to protect against people having zero value but couldn't this be achieved using the built in attribute handling in Gutenberg?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I tried initially, but if you have an empty string, and save the attribute, it will save it with the empty string, not the default value. So this counters that and doesn't let you save the attribute if it's empty.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 30, 2022

Script Dependencies Report

There is no changed script dependency between this branch and trunk.

This comment was automatically generated by the ./github/compare-assets action.

@alexflorisca
Copy link
Member Author

We're waiting on the outcome of this discussion (p1670237870752419/1669983170.345659-slack-C8X6Q7XQU) to merge

@senadir senadir modified the milestones: 9.1.0, 9.2.0 Dec 5, 2022
@nielslange nielslange mentioned this pull request Dec 5, 2022
4 tasks
@github-actions
Copy link
Contributor

This PR has been marked as stale because it has not seen any activity within the past 7 days. Our team uses this tool to help surface pull requests that have slipped through review.

If deemed still relevant, the pr can be kept active by ensuring it's up to date with the main branch and removing the stale label.

@github-actions github-actions bot added the status: stale Stale issues and PRs have had no updates for 60 days. label Dec 13, 2022
@alexflorisca alexflorisca removed the status: stale Stale issues and PRs have had no updates for 60 days. label Dec 13, 2022
@alexflorisca
Copy link
Member Author

Based on the discussion here (pdToLP-f7-p2#comment-163), I'm leaving this as is and merging.

@alexflorisca alexflorisca merged commit 1ea3470 into trunk Dec 13, 2022
@alexflorisca alexflorisca deleted the edit-proceed-to-checkout-button branch December 13, 2022 14:54
@alexflorisca alexflorisca added type: enhancement The issue is a request for an enhancement. block: cart Issues related to the cart block. labels Dec 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block: cart Issues related to the cart block. type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Editing Proceed to Checkout button text in Cart editor page.
3 participants